package com.auto.learning.view;

import java.util.Map;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.auto.learning.R;

public class MyCommentFragmentPopWindowDialog {
	private Context context;
	private LinearLayout layout,linear_support,linear_comment;
	private Map<String, Object> map;
	private IPopDialogOnclickInterface dialogOnclickInterface;
	private PopupWindow popupWindow;
	private int[] location;
	private View parentView;
	private TextView tv_support;
	
	public MyCommentFragmentPopWindowDialog(Context context,Map<String, Object> map,int[] location,View parentView) {
		this.context = context;
		this.map = map;
		this.location = location;
		this.parentView = parentView;
	}
	
	public void setOnClick(IPopDialogOnclickInterface dialogOnclickInterface){
		this.dialogOnclickInterface = dialogOnclickInterface;
	}

	public void showDialog(){
		View view = LayoutInflater.from(context).inflate(R.layout.layout_dialog_comment, null);
		layout = (LinearLayout) view.findViewById(R.id.rel_main);
		linear_support = (LinearLayout) view.findViewById(R.id.linear_support);
		linear_comment = (LinearLayout) view.findViewById(R.id.linear_comment);
		tv_support = (TextView) view.findViewById(R.id.tv_support);
		int isFavour = (int) map.get("isFavour");
		if (isFavour == 2) {
			tv_support.setText("取消赞");
		}else {
			tv_support.setText("赞");
		}
		
		linear_support.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				popupWindow.dismiss();
				dialogOnclickInterface.OnSupportClick(map);
			}
		});
		linear_comment.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				popupWindow.dismiss();
				dialogOnclickInterface.OnRepClick(map);
			}
		});
		popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		popupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
//		popupWindow.showAtLocation(parentView, Gravity.TOP, location[0], location[1]);
		popupWindow.showAsDropDown(view, location[0], location[1]);
	}
	
	public interface IPopDialogOnclickInterface {
		void OnSupportClick(Map<String, Object> map);
		void OnRepClick(Map<String, Object> map);
	}
}
